﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class HoaDonBanSiDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertHDBS(HoaDonBanSiDTO HoaDonBanSi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[14];
            par[0] = new SqlParameter("@MaHDBS", HoaDonBanSi.MaHDBS);
            par[1] = new SqlParameter("@MaKho", HoaDonBanSi.MaKho);
            par[2] = new SqlParameter("@MaKH", HoaDonBanSi.MaKH);
            par[3] = new SqlParameter("@MaNV", HoaDonBanSi.MaNV);
            par[4] = new SqlParameter("@NguoiMua", HoaDonBanSi.NguoiMua);
            par[5] = new SqlParameter("@NgayBanSi", HoaDonBanSi.NgayBanSi);
            par[6] = new SqlParameter("@ChungTuBanSi", HoaDonBanSi.ChungTuBanSi);
            par[7] = new SqlParameter("@GhiChuBS", HoaDonBanSi.GhiChuBS);
            par[8] = new SqlParameter("@DiaChiGiao", HoaDonBanSi.DiaChiGiao);
            par[9] = new SqlParameter("@VAT", HoaDonBanSi.VAT);
            par[10] = new SqlParameter("@TongThanhTien", HoaDonBanSi.TongThanhTien);
            par[11] = new SqlParameter("@SoTienDaTra", HoaDonBanSi.SoTienDaTra);
            par[12] = new SqlParameter("@SoTienConLai", HoaDonBanSi.SoTienConLai);
            par[13] = new SqlParameter("@NgayHenThanhToan", HoaDonBanSi.NgayHenThanhToan);
            try
            {
                helper.InsertQuery("sp_Insert_HoaDonBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateHDBS(HoaDonBanSiDTO HoaDonBanSi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[14];
            par[0] = new SqlParameter("@MaHDBS", HoaDonBanSi.MaHDBS);
            par[1] = new SqlParameter("@MaKho", HoaDonBanSi.MaKho);
            par[2] = new SqlParameter("@MaKH", HoaDonBanSi.MaKH);
            par[3] = new SqlParameter("@MaNV", HoaDonBanSi.MaNV);
            par[4] = new SqlParameter("@NguoiMua", HoaDonBanSi.NguoiMua);
            par[5] = new SqlParameter("@NgayBanSi", HoaDonBanSi.NgayBanSi);
            par[6] = new SqlParameter("@ChungTuBanSi", HoaDonBanSi.ChungTuBanSi);
            par[7] = new SqlParameter("@GhiChuBS", HoaDonBanSi.GhiChuBS);
            par[8] = new SqlParameter("@DiaChiGiao", HoaDonBanSi.DiaChiGiao);
            par[9] = new SqlParameter("@VAT", HoaDonBanSi.VAT);
            par[10] = new SqlParameter("@TongThanhTien", HoaDonBanSi.TongThanhTien);
            par[11] = new SqlParameter("@SoTienDaTra", HoaDonBanSi.SoTienDaTra);
            par[12] = new SqlParameter("@SoTienConLai", HoaDonBanSi.SoTienConLai);
            par[13] = new SqlParameter("@NgayHenThanhToan", HoaDonBanSi.NgayHenThanhToan);
            try
            {
                helper.UpdateQuery("sp_Update_HoaDonBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteHDBS(string maHDBS)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maHDBS", maHDBS);
            try
            {
                helper.DeleteQuery("sp_Delete_HoaDonBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_HoaDonBanSi()
        {
            helper = new Helper();
            DataSet ds_HDBS = helper.SelectQuery("sp_LayDS_HoaDonBanSi");
            return ds_HDBS;
        }
        #endregion
    }
}